﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace Warehouse.UI.WinForm.Controls
{
    public partial class LabelTextBox : UserControl
    {
        public event EventHandler TextBoxTextChanged = null;

        public LabelTextBox()
        {
            InitializeComponent();
        }

        public string LabelText
        {
            get { return label1.Text; }
            set { label1.Text = value; }
        }

        public string TextBoxText
        {
            get { return textBox1.Text; }
            set { textBox1.Text = value; }
        }

        public bool ReadOnly
        {
            get { return textBox1.ReadOnly; }
            set
            {
                textBox1.ReadOnly = value;
                textBox1.BackColor = value ? Color.Honeydew : SystemColors.Window;
            }
        }

        public CharacterCasing CharacterCasing
        {
            get { return textBox1.CharacterCasing; }
            set { textBox1.CharacterCasing = value; }
        }

        public char PasswordChar
        {
            get { return textBox1.PasswordChar; }
            set { textBox1.PasswordChar = value; }
        }

        public Color DefaultColor
        {
            get { return textBox1.BackColor; }
            set { textBox1.BackColor = value; }
        }

        private void LabelTextBox_Resize(object sender, EventArgs e)
        {
            //textBox1.Left = this.LabelWidth + 5;
            //textBox1.Width = this.Width - textBox1.Left-3;
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (TextBoxTextChanged != null) TextBoxTextChanged(textBox1, e);
        }

        private void LabelTextBox_EnabledChanged(object sender, EventArgs e)
        {
            textBox1.BackColor = this.Enabled ? (textBox1.Focused ? Color.Azure : this.DefaultColor) : SystemColors.InactiveBorder;
        }

        private void label1_SizeChanged(object sender, EventArgs e)
        {
            //this.LabelWidth = label1.Width;
            //LabelTextBox_Resize(sender, e);
        }

        private void textBox1_Enter(object sender, EventArgs e)
        {
            textBox1.BackColor = Color.Azure;
            textBox1.SelectAll();
        }

        private void textBox1_Leave(object sender, EventArgs e)
        {
            textBox1.BackColor = SystemColors.Window;
        }
    }
}
